package cn.bear.spring_boot_study.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.Collections;

/**
 * 简单代码生成器
 * 
 * @author bear
 * @since 2024-01-01
 */
public class SimpleCodeGenerator {
    
    public static void main(String[] args) {
        // 获取项目路径
        String projectPath = System.getProperty("user.dir");
        
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/world?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8", 
                                "root", "1234....")
                .globalConfig(builder -> {
                    builder.author("bear")
                            .outputDir(projectPath + "/src/main/java")
                            .disableOpenDir()
                            .dateType(DateType.ONLY_DATE);
                })
                .packageConfig(builder -> {
                    builder.parent("cn.bear.spring_boot_study")
                            .moduleName("system")
                            .entity("entity")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, projectPath + "/src/main/resources/mapper/system/"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude("city", "country")
                            .entityBuilder()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableRestStyle()
                            .enableHyphenStyle();
                })
                .execute();
        
        System.out.println("代码生成完成！");
    }
}